package a03demo3;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test1 {
    public static void main(String[] args) {
        ArrayList<String> list1 = new ArrayList<>();
        Collections.addAll(list1, "abc,24", "bcc,23", "wca,22", "bb,24");

        ArrayList<String> list2 = new ArrayList<>();
        Collections.addAll(list2, "cba,35", "acb,36", "abc,33");

        Stream<String> b = list1.stream()
                .filter(s -> s.split(",")[0].length() == 3)
                .limit(2);


        Stream<String> a = list2.stream()
                .filter(s -> s.split(",")[0].startsWith("a"))
                .skip(1);


//    1.    Stream.concat(b, a).map(new Function<String, Actor>() {
//            @Override
//            public Actor apply(String s) {
//                String name = s.split(",")[0];
//                int age = Integer.parseInt(s.split(",")[1]);
//                return new Actor(name,age);
//            }
//        }).forEach(s-> System.out.println(s));


//     2.   Stream.concat(b, a).map(s -> {
//            String name = s.split(",")[0];
//            int age = Integer.parseInt(s.split(",")[1]);
//            return new Actor(name, age);
//        }).forEach(s -> System.out.println(s));


        List<Actor> list = Stream.concat(b, a).map(s -> new Actor(s.split(",")[0], Integer.parseInt(s.split(",")[1])))
                .collect(Collectors.toList());
        System.out.println(list);

    }
}

class Actor {
    private String name;
    private int age;


    public Actor() {
    }

    public Actor(String name, int age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return age
     */
    public int getAge() {
        return age;
    }

    /**
     * 设置
     *
     * @param age
     */
    public void setAge(int age) {
        this.age = age;
    }

    public String toString() {
        return "Actor{name = " + name + ", age = " + age + "}";
    }
}